<?php
require_once 'Mobitv/Admin/Action.php';
class IndexAction extends Mobitv_Admin_Action{
    public function execute(){
        $this->checkPermission();
        $this->updateLoginStatus();
        $limit  = $this->_config['user']['items_per_page'];
        $page   = isset($_GET['page']) ? intval($_GET['page']) : 1;
        $group_admin = isset ($_GET['group'])? $_GET['group'] : '';
        $this->_view->assign('group', $group_admin);
        $txtSearch = isset ($_GET['text'])? $_GET['text'] : '';
        $txtSearch = strip_tags($txtSearch);
        $this->_view->assign('text', $txtSearch);
        $deleted = isset ($_GET['deleted'])? $_GET['deleted'] : 0;
        $this->_view->assign('deleted', $deleted);

        $groupDao = Vega_Dao::factory('Mobitv_Admin_Group');
        $groups = $groupDao->getList();
        $this->_view->assign('groups', $groups);
        
        $userDao = Vega_Dao::factory('Mobitv_Admin_Admin');
        $users = $userDao->getList($limit, $page, $group_admin, $deleted, $txtSearch);
        $arrGroup = $userDao->getGroupList();
        $numberUser = $userDao->countAll($group_admin, $deleted, $txtSearch);
        
        $this->_view->assign('users', $users);
        $this->_view->assign('arrGroup', $arrGroup);
        $this->_view->assign('curPage', $page);
        $totalPage = ceil($numberUser / $limit);
        $this->_view->assign('totalPage', $totalPage);
    }
}